//
//  UserVC.swift
//  DollarBuy
//
//  Created by 郑东喜 on 2016/11/7.
//  Copyright © 2016年 郑东喜. All rights reserved.
//  用户登陆主界面

import UIKit


class UserVC: MeBaseViewController {

    
//    微信工具类
    let wxtool = WXTool()
    
    @IBAction func xgPassSEL(_ sender: UIButton) {
        self.navigationController?.pushViewController(ChangePassVC(), animated: true)
    }
    
    //用户名
    @IBOutlet weak var tfNum: UITextField!
    
    //密码
    @IBOutlet weak var tfPass: UITextField!
    

}

// MARK:- 加载本地数据
extension UserVC {
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        //加载本地 用户名 --- 便于测试
        if localSave.object(forKey: localName) as? String != nil {
            self.tfNum.text = localSave.object(forKey: localName) as? String
        } else {
            return
        }
        
        //加载本地 用户名密码
        if localSave.object(forKey: localPass) as? String != nil {
            self.tfPass.text = localSave.object(forKey: localPass) as? String
        } else {
            return
        }

    
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        
        NotificationCenter.default.removeObserver(self)
        print("移除通知")
    }
    
}




// MARK:- 跳转接口
extension UserVC {
    //qq登录
    @IBAction func qqLogin(_ sender: UIButton) {
        print("\((#file as NSString).lastPathComponent):(\(#line)):(\("qq登录")))")

        QQTool.qqTool.qqLogin()
        
        self.navigationController?.pushViewController(MeViewController(), animated: true)
        
        //qq登陆
        QQLogin.shared.qqObserver()

    }
    
    
    //微信登录
    @IBAction func wechatLogin(_ sender: UIButton) {
        print("\((#file as NSString).lastPathComponent):(\(#line)):(\("微信登录")))")
        
        wxtool.clickAuto()
        
        //微信登陆
        WXLogin.shared.wxObserver()
        
        self.navigationController?.pushViewController(MeViewController(), animated: true)
    }

    //登陆
    @IBAction func loginSEL(_ sender: UIButton) {
        /**
         ## 登陆
         主要实现了登陆封装逻辑
         
         - tfNum    电话号码
         - tfPass   密码
         */
        self.login(tfNum: self.tfNum, tfPass: self.tfPass)
    }

    
    //注册
    @IBAction func rigSEL(_ sender: UIButton) {
        self.navigationController?.pushViewController(RigisterVC(), animated: true)
        print("\((#file as NSString).lastPathComponent):(\(#line)):(\("跳转注册成功")))")
    }
    
    //重置密码
    @IBAction func resetSEL(_ sender: UIButton) {
        self.navigationController?.pushViewController(ForgetVC(), animated: true)
        print("\((#file as NSString).lastPathComponent):(\(#line)):(\("跳转重置密码成功")))")
    }

}





